home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / DataScope 2.0.3 / Datafiles / externs / Mac_externs / greater.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-04  |  1.5 KB  |  76 lines  |  [TEXT/MPS ]

  1. #include "DScope.h"
  2. /*
  3.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4.     greater    Given 2 arrays or 2 constants or a constant
  5.             and an array, the output is the greater value;
  6.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. */
  8. long addon(l,r,a)
  9.     scope_array            *l,*r,*a;
  10. {
  11.     register float        *p,*q,*s,*t;
  12.  
  13.     if (!l || !r)
  14.        {a->kind = DS_ERROR;
  15.         return(0);
  16.        }
  17.        
  18.     if (l->kind == DS_CONSTANT && r->kind == DS_CONSTANT)
  19.        {a->kind = DS_CONSTANT;
  20.         if (l->cval > r->cval)    a->cval = l->cval;
  21.         else                    a->cval = r->cval;
  22.         return (0);
  23.        }
  24.        
  25.     if (l->kind == DS_CONSTANT)
  26.        {p = r->vals;
  27.         q = p + (long)(r->ncols * r->nrows - 1);
  28.         t = a->vals;
  29.         while (p < q)
  30.               {if (*p > l->cval)    *t++ = *p++;
  31.                else
  32.                        {*t++ = l->cval;
  33.                      p++;
  34.                     }
  35.               }
  36.         if (*p > l->cval)    *t = *p;
  37.         else                *t = l->cval;
  38.         return (0);
  39.        }
  40.     
  41.     if (r->kind == DS_CONSTANT)
  42.        {p = l->vals;
  43.         q = p + (long)(l->ncols * l->nrows - 1);
  44.         t = a->vals;
  45.         while (p < q)
  46.               {if (*p > r->cval)    *t++ = *p++;
  47.                else
  48.                        {*t++ = r->cval;
  49.                      p++;
  50.                     }
  51.               }
  52.         if (*p > r->cval)    *t = *p;
  53.         else                *t = r->cval;
  54.         return (0);
  55.        }
  56.     
  57.     if (l->nrows != r->nrows || l->ncols != r->ncols)
  58.        {a->kind = DS_ERROR;
  59.         return (0);
  60.        }
  61.     p = l->vals;
  62.     q = p + (long)(l->ncols * l->nrows - 1);
  63.     s = r->vals;
  64.     t = a->vals;
  65.     while (p < q)
  66.           {if (*p > *s)        *t++ = *p;
  67.            else                *t++ = *s;
  68.            p++;
  69.            s++;
  70.           }
  71.     if (*p > *s)    *t = *p;
  72.     else            *t = *s;
  73.     return (0);
  74. }
  75.  
  76.